namespace My
{
    template<class T>
    class auto_ptr
    {
    public:
        auto_ptr(T* ptr = nullptr)
            :_ptr(ptr)
        {}

        ~auto_ptr()
        {
            if (_ptr)
            {
                cout << "auto_delete:" << _ptr << endl;
                delete _ptr;
            }
        }

        auto_ptr<T>& operator=(auto_ptr<T>& ap)
        {
            if (this != &ap)
            {
                if (_ptr)
                {
                    cout << "operator=()delete:" << _ptr << endl;
                    delete _ptr;
                }

                _ptr = ap._ptr;
                ap._ptr = nullptr;

                return *this;
            }
        }

        auto_ptr(auto_ptr<T>& ap)
            :_ptr(ap.ptr)
        {
            ap._ptr = nullptr;
        }

        T& operator*() { return *_ptr; }
        T* operator->() { return _ptr; }

    private:
        T* _ptr;
    };
}
